Modifying enumeration types in-place

I want to modify the values of an enumeration AttrType (adding new values, reordering). The AttrType is used already by an AttrDef, so I use the modify perms with remapping:

  • AttrType modify(AttrType oldAttrType, string newName, string[] newStrings, int[] newValues, int[] newColors, int[] remapping, string& errMsg) 
  • AttrType modify(AttrType oldAttrType, string newName, Array array, string& errMag)

But I cannot cope with the newName parameter. Some examples state that newName can be the old type name (like in the DXL manual 9.3 p. 452f. or in this entry), but in my case both modify variants returns the error (in german): "Sie haben einen doppelten Typnamen '<typename>' angegeben." (You have given/entered a double type name).

When I take another name a new AttrType with the new name is created as expected. Also the existing AttrDefs will be changed to that new AttrType. But the old type is still there. So I could delete the old type and modify the new type again (with AttrType modify(AttrType, string)) to get the original name, but this cannot be the intended workflow.

Is it not possible to change an AttrType in place?

 

Uwe


UweR - Fri Nov 13 08:37:14 EST 2015

Re: Modifying enumeration types in-place
Mathias Mamsch - Fri Nov 13 15:31:11 EST 2015

It should be possible and you should double check, that the AttrType you are passing to the function is correct. Or you might have a bug in DOORS. Some example code might be helpful for helping. Regards, Mathias

Re: Modifying enumeration types in-place
Wolfgang Uhr - Sun Nov 15 12:41:01 EST 2015

Hi

If you use the remapping-parameter, you have to use the largest-modify, that means: Even if the "description" parameters are allways empty lines, you have to add this parameter array. And then you can use the value of the old name for newName.

Best regards

Wolfgang

Re: Modifying enumeration types in-place
UweR - Mon Nov 16 05:29:30 EST 2015

I use following function for the modification. srcEnumType and destEnumType are AttrTypes from different modules. I've added the changedValue flag, because modify crashes DOORS when there is no change at all. I use DOORS version  9.3.0.0 (Build 93199) but I have to be compatible with 8.x and 9.x.

I added the descriptions as Wolfgang suggested, but with no success: I get the same error message.

AttrType updateEnumerationValues(AttrType srcEnumType, AttrType destEnumType) {
 setRealColorOptionForTypes(true); 

 int i,j;

 // find array size
 int newEnumTypeSize = srcEnumType.size;

 Skip attrTypeNames = createString();
 for (i = 0; i < srcEnumType.size; i++) {
  put(attrTypeNames, srcEnumType.strings[i], 0);
 }
 for (j = 0; j < destEnumType.size; j++) {
  if (find(attrTypeNames, destEnumType.strings[j]) == false) {
   newEnumTypeSize++;
  }
 }

 string newStrings[newEnumTypeSize];
 int newValues[newEnumTypeSize];
 int newColors[newEnumTypeSize];
 int remapping[newEnumTypeSize];
 string descr[newEnumTypeSize];

 // contains the updates enum indices of the destination type
 Skip usedDestEnumValues = create();

 bool changedValues = false;

 // add enum values existing at least in source type
 int pos;
 for (i = 0; i < srcEnumType.size; i++) {
  string enumValue = srcEnumType.strings[i];
  newStrings[i] = enumValue;
  newValues[i] = srcEnumType.values[i];
  newColors[i] = srcEnumType.colors[i];
  descr[i] = srcEnumType.descriptions[i];

  // find enum value with the same name in dest type
  pos = -1;
  for (j = 0; j < destEnumType.size && pos == -1; j++) {
   if (destEnumType.strings[j] == enumValue) {
    pos = j;
    put(usedDestEnumValues, pos, 0);
   }
  }

  if (pos == -1) {
   changedValues = true;
  }

  remapping[i] = pos;
 }

 // add enum values existing only in destination type
 int insertPos = srcEnumType.size;
 for (j = 0; j < destEnumType.size; j++) {
  if (find(usedDestEnumValues, j) == false) {
   changedValues = true;

   newStrings[insertPos] = destEnumType.strings[j];
   newValues[insertPos] = destEnumType.values[j];
   newColors[insertPos] = destEnumType.colors[j];
   descr[insertPos] = destEnumType.descriptions[j];
   remapping[insertPos] = j;

   insertPos++;
  }
 }

 if (changedValues) {
  string destEnumTypeName = destEnumType.name

  string errMsg
  // AttrType modifiedDestEnumType = modify(destEnumType, destEnumTypeName, newStrings, newValues, newColors, remapping, errMsg);
  AttrType modifiedDestEnumType = modify(destEnumType, destEnumTypeName, newStrings, newValues, newColors, descr, remapping, errMsg);
  if (null(modifiedDestEnumType) || null(errMsg) == null) {
   print "Error while modifying enumeration type " destEnumTypeName ": " errMsg "\n";
  } 
 }

 delete usedDestEnumValues;
 delete modifyArray;

 return modifiedDestEnumType;
}

Re: Modifying enumeration types in-place
UweR - Thu Nov 16 07:17:56 EST 2017

For some reason I came back to this problem and found the solution now. I had forgotten to set the current module to the target module. So perhaps the perm tried to modify the attribute type in the source module. So the in-place modification of the enumeration type works now.